<template>
	<view>
		<top-navigation bgColor="'transparent'" :imgSrc="$getImgUrl() + accompanyImg" :isBack="showBackicon">
			<template #left-slot>
			</template>
		</top-navigation>
		<view class="list">
			<view class="item" v-for="(item,index) in list" :key="index" @click="toDetail(item)">
				<image :src="$getImgUrl()+item.cover"></image>
				<view class="title">
					{{item.name}}
				</view>
				<view class="instructions">{{item.recommend}}</view>
				<view class="price">
					<text class="num">{{item.is_price ? (item.original_price || '--') : (item.price || '--')}}</text>
					元/次
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		areaClass
	} from '@/config/config.js'

	import {
		mapGetters
	} from "vuex";
	export default {
		data() {
			return {
				list: [],
				accompanyImg: '',
				showBackicon: true
			};
		},
		onPageScroll(e) {
			this.showBackicon = e.scrollTop > 10 ? false : true
		},
		created() {
			this.getProjectList();
			this.getConfig()
		},
		computed: {
			...mapGetters(["curAddress"])
		},
		methods: {
			getProjectList() {
				let params = {
					is_extra: '3'
				}
				if (areaClass == '1') {
					params.city_code = this.curAddress.cityCode
				} else if (areaClass == '2') {
					params.area_code = this.curAddress.areaCode
				}
				console.warn(params)
				this.$request('/applet/index/page/getProject', params).then(res => {
					console.log("获取详细项目", res)
					if (res.code == 200) {
						this.list = res.data;
					}
				})
			},
			//获取就诊陪诊背景图
			getConfig() {
				this.$request('/applet/index/page/getConfig', {
					type: '3'
				}).then(res => {
					console.log("获取陪诊", res)
					if (res.code == 200) {
						this.accompanyImg = res.data.content
					}
				})
			},
			toDetail(item) {
				if ((item.is_price && !item.original_price) || (!item.is_price && !item.price)) {
					return uni.$toast('该服务暂无开通')
				}
				this.$navto('/pages/order/project-info?id=' + item.id, true)
			}
		},
	}
</script>

<style lang="scss" scoped>
	page {
		background: #F6F7FB;
	}

	.title-bg {
		width: 100%;
		height: 580rpx;
	}

	.list {
		position: relative;
		bottom: 180rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		padding: 0 30rpx;
		z-index: 9;

		.item:nth-child(1) {
			margin-top: -70rpx;
		}

		.item:nth-child(2) {
			margin-top: -70rpx;
		}

		.item {
			width: 332rpx;
			background: #FFFFFF;
			box-shadow: 0px 2rpx 18rpx 0px rgba(0, 0, 0, 0.06);
			border-radius: 20rpx;
			padding: 30rpx;
			box-sizing: border-box;
			margin-bottom: 70rpx;
			z-index: 9;

			image {
				margin-top: -60rpx;
				width: 272rpx;
				height: 272rpx;
				border-radius: 20rpx;
				margin-bottom: 30rpx;
			}

			.title {
				font-size: 30rpx;
				font-weight: bold;
				color: #333333;
				margin-bottom: 21rpx;
			}

			.instructions {
				font-size: 24rpx;
				font-weight: 500;
				height: 65rpx;
				color: #666666;
				margin-bottom: 30rpx;
				letter-spacing: 0;
				overflow: hidden;
				display: -webkit-box;
				text-overflow: ellipsis;
				-webkit-line-clamp: 2;
				/*要显示的行数*/
				-webkit-box-orient: vertical;
			}

			.price {
				font-size: 24rpx;
				font-weight: 500;
				color: #333333;

				.num {
					font-size: 36rpx;
					font-weight: bold;
					color: #FF4D4D;
					margin-right: 12rpx;
				}
			}
		}
	}
</style>
